<!doctype html>
<html lang="zh-cn">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<title>山海境花-悬赏查询工具</title>
		<link href="./index.css" rel="stylesheet">
		<script type="text/javascript" src="./guess.json"></script>
		<script type="text/javascript" src="./data.json"></script>
		<script type="text/javascript">
			function trim(val) {
				if (val) {
					val = val.trim()
				}
				return val
			}
			function findAll() {

				document.getElementById('guess-tip').style.display = 'none'
				document.getElementById('result-content1').parentElement.style.display = 'none'
				document.getElementById('result-content2').parentElement.style.display = 'none'
				document.getElementById('result-content3').parentElement.style.display = 'none'
				document.getElementById('result-content4').parentElement.style.display = 'none'
				// document.getElementById('result-content5').parentElement.style.display = 'none'
				document.getElementById('result-content6').parentElement.style.display = 'none'

				var word = trim(document.getElementById('word').value)
				if (!word) {
					return
				}

				if (!find(word)) {
					// 根据线索
					var guessSome = guess.filter(item=>item.from.indexOf(word)>=0)
					if (guessSome && guessSome.length > 0) {
						word = guessSome[0].to
						document.getElementById('guess-tip').innerText = `${guessSome[0].from} >>> ${guessSome[0].to}`
						document.getElementById('guess-tip').style.display = ''
						find(word)
					} else {
						document.getElementById('guess-tip').style.display = 'none'
					}
				}
			}

			function find(word) {
				// 历练
				var result1 = search(data1, word)
				if (result1 !== '') {
					document.getElementById('result-content1').innerHTML = result1
					document.getElementById('result-content1').parentElement.style.display = ''
				}
				// 灾祸之渊
				var result2 = search(data2, word)
				if (result2 !== '') {
					document.getElementById('result-content2').innerHTML = result2
					document.getElementById('result-content2').parentElement.style.display = ''
				}
				// 昆仑之墟
				var result3 = search(data3, word)
				if (result3 !== '') {
					document.getElementById('result-content3').innerHTML = result3
					document.getElementById('result-content3').parentElement.style.display = ''
				}
				// 异闻秘录
				var result4 = search(data4, word)
				if (result4 !== '') {
					document.getElementById('result-content4').innerHTML = result4
					document.getElementById('result-content4').parentElement.style.display = ''
				}
				// 大荒战图
				// var result5 = search(data5, word)
				// if (result5 !== '') {
				// 	document.getElementById('result-content5').innerHTML = result5
				// 	document.getElementById('result-content5').parentElement.style.display = ''
				// }
				// 聆训阁
				var result6 = search(data6, word)
				if (result6 !== '') {
					document.getElementById('result-content6').innerHTML = result6
					document.getElementById('result-content6').parentElement.style.display = ''
				}

				if (!result1 && !result2 && !result3 && !result4 && !result5 && !result6)
					return false
				else
					return true
			}

			function search(data, kw) {
				var result = data.filter(item=>{return item.jl.indexOf(kw)>=0})
				var resultHtml = '';
				if (result && result.length > 0) {
					for (var i = 0; i < result.length; i++) {
						var item = result[i]
						resultHtml += `<p>${item.fb}：${item.jl}（${item.cnt}）</p>`
					}
				}
				return resultHtml
			}
		</script>
	</head>
	<body>
		<span>镜灵或线索：</span><input type="text" name="word" id='word'>
 		<button onclick="findAll()">查找</button>
		<p id="guess-tip"></p>
		<div class="result-box">
			<p>聆训阁</p>
			<div id="result-content6" class="result-content">
			</div>
		</div>
 		<div class="result-box">
			<p>灾祸之渊</p>
			<div id="result-content2" class="result-content">
			</div>
 		</div>
 		<div class="result-box">
			<p>昆仑之墟</p>
			<div id="result-content3" class="result-content">
			</div>
 		</div>
 		<div class="result-box">
			<p>异闻秘录</p>
			<div id="result-content4" class="result-content">
			</div>
 		</div>
<!-- 		<div class="result-box">-->
<!--			<p>大荒战图</p>-->
<!--			<div id="result-content5" class="result-content">-->
<!--			</div>-->
<!-- 		</div>-->
		<div class="result-box">
			<p>历练</p>
			<div id="result-content1" class="result-content">
			</div>
		</div>
		<div class="blank-row"></div>
		<footer>
			最后更新时间：2020-06-11
			<br>*数据来源：<a href="https://www.taptap.com/topic/12731478" target="_blank">TapTap 不胖十斤不改名</a>。问题反馈：<a href="https://gitee.com/523757325/shanhaijinghuagongju/issues" target="_blank">项目地址</a>
		</footer>
	</body>
</html>
